<extend name="Public:base" />
<block name="content">

<div class="container-fluid">

	<!-- BEGIN PAGE HEADER-->   

	<div class="row-fluid">

		<div class="span12">
			
            <div class="color-panel hidden-phone">

                <div class="color-mode-icons icon-color"></div>

                <div class="color-mode-icons icon-color-close" style="display: none;"></div>

                <div class="color-mode" style="display: none;">

                    <p>THEME COLOR</p>

                    <ul class="inline">

                        <li class="color-black color-default current" data-style="default"></li>

                        <li class="color-blue" data-style="blue"></li>

                        <li class="color-brown" data-style="brown"></li>

                        <li class="color-purple" data-style="purple"></li>

                        <li class="color-grey" data-style="grey"></li>

                        <li class="color-white color-light" data-style="light"></li>

                    </ul>

                    <label>

                        <span>Layout</span>

                        <select class="layout-option m-wrap small">

                            <option value="fluid" selected="">Fluid</option>

                            <option value="boxed">Boxed</option>

                        </select>

                    </label>

                    <label>

                        <span>Header</span>

                        <select class="header-option m-wrap small">

                            <option value="fixed" selected="">Fixed</option>

                            <option value="default">Default</option>

                        </select>

                    </label>

                    <label>

                        <span>Sidebar</span>

                        <select class="sidebar-option m-wrap small">

                            <option value="fixed">Fixed</option>

                            <option value="default" selected="">Default</option>

                        </select>

                    </label>

                    <label>

                        <span>Footer</span>

                        <select class="footer-option m-wrap small">

                            <option value="fixed">Fixed</option>

                            <option value="default" selected="">Default</option>

                        </select>

                    </label>

                </div>

            </div>

			<h3 class="page-title">

				Blog

				 <small>Blog分类管理和更多</small>

			</h3>

			<ul class="breadcrumb">

				<li>

					<i class="icon-home"></i>

					<a href="index.html">首页</a> 

					<span class="icon-angle-right"></span>

				</li>

				<li><a href="/admin/blog/type/index">Blog分类管理</a></li>

			</ul>

		</div>

	</div>

	<!-- END PAGE HEADER-->

	<!-- BEGIN PAGE CONTENT-->

	<div class="row-fluid">

		<div class="span12">

			<!-- BEGIN SAMPLE FORM PORTLET-->   

			<div class="portlet box blue tabbable">

				<div class="portlet-title">

					<div class="caption">

						<i class="icon-reorder"></i>

						<span class="hidden-480">Blog分类管理</span>

					</div>

				</div>

				<div class="portlet-body form">

					<div class="tabbable portlet-tabs">

						<ul class="nav nav-tabs" name="ul">

							<li><a href="#portlet_tab3" data-toggle="tab">修改分类</a></li>

							<li><a href="#portlet_tab2" data-toggle="tab">添加分类</a></li>

							<li class="active"><a href="#portlet_tab1" data-toggle="tab">浏览分类</a></li>

						</ul>

						<div class="tab-content">

							<div class="tab-pane active" id="portlet_tab1">

								<!-- BEGIN FORM-->
								<form action="#" class="form-horizontal">
									<div class="portlet-body">

										<div id="sample_2_wrapper" class="dataTables_wrapper form-inline" role="grid">
											
											<table class="table table-striped table-bordered table-hover table-full-width dataTable" id="sample_2" aria-describedby="sample_2_info">

												<thead>

													<tr role="row">
														<th class="sorting" role="columnheader" tabindex="0" aria-controls="sample_2" rowspan="1" colspan="1" aria-label="Rendering engine: activate to sort column ascending" style="width: 209px;">ID</th>
														<th class="sorting_asc" role="columnheader" tabindex="0" aria-controls="sample_2" rowspan="1" colspan="1" aria-sort="ascending" aria-label="Browser: activate to sort column descending" style="width: 276px;">类名</th>
														<th class="hidden-480 sorting" role="columnheader" tabindex="0" aria-controls="sample_2" rowspan="1" colspan="1" aria-label="Platform(s): activate to sort column ascending" style="width: 259px;">所属父类</th>
														<th class="hidden-480 sorting" role="columnheader" tabindex="0" aria-controls="sample_2" rowspan="1" colspan="1" aria-label="Engine version: activate to sort column ascending" style="width: 179px;">添加操作</th>
														<th class="hidden-480 sorting" role="columnheader" tabindex="0" aria-controls="sample_2" rowspan="1" colspan="1" aria-label="CSS grade: activate to sort column ascending" style="width: 127px;">修改操作</th>
														<th class="hidden-480 sorting" role="columnheader" tabindex="0" aria-controls="sample_2" rowspan="1" colspan="1" aria-label="CSS grade: activate to sort column ascending" style="width: 127px;">删除操作</th>
													</tr>

												</thead>

												

												<tbody role="alert" aria-live="polite" aria-relevant="all">
													<foreach name="list" item="vo" key="k" >
														<if condition="($k%2 eq 0)">
															<tr class="even">
														<else />
															<tr class="odd">
														</if>
														
															<td class=" ">{$vo['id']}</td>

															<td class=" sorting_1">{$vo['type_name']}</td>

															<td class="hidden-480 "><if condition="($vo['pid'] eq 0)">顶级类<else/>{:getFu($vo['pid'])}</if></td>

															<td name="add" class="hidden-480 "><a href="" title="添加该类的子类" class="icon-plus"> 添加</a></td>

															<td name="edit" class="hidden-480 "><a href="" title="修改该类的类名， 注意：修改此类名的同时，如果该类有子类，其父类名也随之更改" class="icon-edit"> 修改</a></td>

															<td name="del" class="hidden-480 "><a href="" title="删除该类，注意：如果该类有子类，则不可以删除" class="icon-trash"> 删除</a></td>

														</tr>
													</foreach>
												</tbody>
											</table>
											
										</div>

									</div>

								</form>

								<!-- END FORM-->  

							</div>

							<div class="tab-pane " id="portlet_tab2">

								<form class="form-horizontal">

									<div class="control-group">

										<label class="control-label">父类名</label>

										<div class="controls">

											<select name="add" class="large m-wrap" tabindex="1">

													<option value="0">顶级类</option>

												<foreach name="list" item="vo" >

													<option value="{$vo['id']}">{$vo['type_name']}</option>

												</foreach>>

											</select>

										</div>

									</div>

									<div class="control-group">

										<label class="control-label">子类名</label>

										<div class="controls">

											<input name="type_name" type="text" placeholder="large" class="m-wrap large">

											<span class="help-inline">Some hint here</span>

										</div>

									</div>
									
									<div class="form-actions">

										<button type="submit" name="add" class="btn blue"><i class="icon-ok"></i> Save</button>

										<button type="button" class="btn">Cancel</button>

									</div>
								

								</form>

							</div>

							<div class="tab-pane " id="portlet_tab3">

								<form class="form-horizontal">

									<div class="control-group">

										<label class="control-label">原类名</label>

										<div class="controls">

											<select name="edit" class="large m-wrap" tabindex="1">


												<foreach name="list" item="vo" >

													<option value="{$vo['id']}">{$vo['type_name']}</option>

												</foreach>>

											</select>

										</div>

									</div>

									<div class="control-group">

										<label class="control-label">现类名</label>

										<div class="controls">

											<input type="text" name="type_name1" placeholder="large" class="m-wrap large">

											<span class="help-inline">Some hint here</span>

										</div>

									</div>
									
									<div class="form-actions">

										<button type="submit" name="edit" class="btn blue"><i class="icon-ok"></i> Save</button>

										<button type="button" class="btn">Cancel</button>

									</div>

								</form>

							</div>

						</div>

					</div>

				</div>

			</div>

			<!-- END SAMPLE FORM PORTLET-->

		</div>

	</div>

	<!-- END PAGE CONTENT-->         

</div>
<div id="lvjing">
</div>
<div id='tishi'>

</div>
<script type="text/javascript" src="__PUBLIC__/admin/js/jquery-1.8.3.min.js"></script>
<script type="text/javascript">
	// alert($);
	// $('ul[name="ul"]').find('li').
	$('td[name="add"]').each(function(){
		$(this).click(function(){
			// var addId=$(this).parent().first().html();
			var addId=$(this).siblings().html();
			// alert(addId);
			$('ul[name="ul"] li').removeAttr('class');
			$('ul[name="ul"] li:eq(1)').attr('class','active');
			$('#portlet_tab1').attr('class','tab-pane');
			$('#portlet_tab3').attr('class','tab-pane');
			$('#portlet_tab2').attr('class','tab-pane active');
			$('select[name="add"]').val(addId);
			return false;
		});
	});
	$('td[name="edit"]').each(function(){
		$(this).click(function(){
			var editId=$(this).siblings().html();
			// alert(editId);
			$('ul[name="ul"] li').removeAttr('class');
			$('ul[name="ul"] li:eq(0)').attr('class','active');
			$('#portlet_tab1').attr('class','tab-pane');
			$('#portlet_tab2').attr('class','tab-pane');
			$('#portlet_tab3').attr('class','tab-pane active');
			$('select[name="edit"]').val(editId);
			return false;
		});
	});



	$('button[name="add"]').click(function(){
		var pid=$('select[name="add"]').val();
		var type_name=$('input[name="type_name"]').val();
		$.ajax({
			url:"/admin/blog/type/insert",
			data:{'pid':pid,'type_name':type_name},
			type:"post",
			success:function(mes){
				// alert(mes);
				if(mes=='yes'){
					$('#lvjing').css('display','block');
					$("#tishi").css('display','block');
		            $("#tishi").html('<span style="color:red;">添加成功,1秒后自动关闭</span>');
		            setTimeout(function(){
			            $('#lvjing').css('display','none');
			            $("#tishi").css('display','none');
			            location.href="{:U('admin/blog/type/index')}";
		            },1000);
				}else{
					$('#lvjing').css('display','block');
					$("#tishi").css('display','block');
		            $("#tishi").html('<span style="color:red;">添加失败,1秒后自动关闭</span>');
		            setTimeout(function(){
			            $('#lvjing').css('display','none');
			            $("#tishi").css('display','none');
		            },1000);
				}
			},
		});
		return false;
	});

	$('button[name="edit"]').click(function(){
		// alert('aaaa');
		var id=$('select[name="edit"]').val();
		var type_name=$('input[name="type_name1"]').val();
		$.ajax({
			url:"/admin/blog/type/update",
			data:{'id':id,'type_name':type_name},
			type:"post",
			success:function(mes){
				// alert(mes);
				if(mes=='yes'){
					$('#lvjing').css('display','block');
					$("#tishi").css('display','block');
		            $("#tishi").html('<span style="color:red;">修改成功,1秒后自动关闭</span>');
		            setTimeout(function(){
			            $('#lvjing').css('display','none');
			            $("#tishi").css('display','none');
			            location.href="{:U('admin/blog/type/index')}";
		            },1000);
				}else{
					$('#lvjing').css('display','block');
					$("#tishi").css('display','block');
		            $("#tishi").html('<span style="color:red;">修改失败,1秒后自动关闭</span>');
		            setTimeout(function(){
			            $('#lvjing').css('display','none');
			            $("#tishi").css('display','none');
		            },1000);
				}
			},
		});
		return false;
	});

	$('td[name="del"]').click(function(){
		var delId=$(this).siblings().html();
		$.ajax({
			url:"/admin/blog/type/delete",
			data:{'id':delId},
			type:"post",
			success:function(mes){
				console.log(mes);
				if(mes=='yes'){
					$('#lvjing').css('display','block');
					$("#tishi").css('display','block');
		            $("#tishi").html('<span style="color:red;">删除成功,1秒后自动关闭</span>');
		            setTimeout(function(){
			            $('#lvjing').css('display','none');
			            $("#tishi").css('display','none');
			            location.href="{:U('admin/blog/type/index')}";
		            },1000);
				}else if(mes=='no'){
					$('#lvjing').css('display','block');
					$("#tishi").css('display','block');
		            $("#tishi").html('<span style="color:red;">删除失败,1秒后自动关闭</span>');
		            setTimeout(function(){
			            $('#lvjing').css('display','none');
			            $("#tishi").css('display','none');
		            },1000);
				}else if(mes=='canot'){
					$('#lvjing').css('display','block');
					$("#tishi").css('display','block');
		            $("#tishi").html('<span style="color:red;">该类别含有子类，不可以删除,1秒后自动关闭</span>');
		            setTimeout(function(){
			            $('#lvjing').css('display','none');
			            $("#tishi").css('display','none');
		            },1000);
				}
			}
		});
		return false;
	});

	$('input[name="keyword"]').keyup(function(){
		var keyword=$(this).val();
		$.ajax({
			url:"/admin/blog/type/select",
			data:{'keyword':keyword},
			type:"post",
			success:function(mes){
				console.log(mes);
			}
		});
	});
		
</script>

</block>